/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.to.aboomy.bannersample.indicator;

import com.bumptech.glide.Glide;
import ohos.agp.components.AttrSet;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.StackLayout;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

/**
 * BannerBgContainer
 *
 * @since 2021-07-29
 */
public class BannerBgContainer extends DependentLayout {
    private static final int NUM560 = 560;

    private List<BannerBgView> bannerBgViews = new ArrayList<>();

    /**
     * 构造函数
     *
     * @param context 上下文
     */
    public BannerBgContainer(Context context) {
        this(context, null);
    }

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param attrs 属性
     */
    public BannerBgContainer(Context context, AttrSet attrs) {
        this(context, attrs, null);
    }

    /**
     * 构造函数
     *
     * @param context 上下文
     * @param attrs 属性
     * @param styleName 样式名称
     */
    public BannerBgContainer(Context context, AttrSet attrs, String styleName) {
        super(context, attrs, styleName);
    }

    public List<BannerBgView> getBannerBgViews() {
        return this.bannerBgViews;
    }

    /**
     * 设置
     *
     * @param context context
     * @param bgUrlList bgUrlList
     */
    public void setBannerBackBg(Context context, List<Integer> bgUrlList) {
        bannerBgViews.clear();
        this.removeAllComponents();
        StackLayout.LayoutConfig layoutParams =
                new StackLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,NUM560);
        for (Object urlImageView : bgUrlList) {
            BannerBgView bannerBgView = new BannerBgView(context);
            bannerBgView.setLayoutConfig(layoutParams);
            Glide.with(context).load(urlImageView).centerCrop().into(bannerBgView.getImageView());
            bannerBgViews.add(bannerBgView);
            this.addComponent(bannerBgView);
        }
        this.moveChildToFront(bannerBgViews.get(0));
    }
}
